<?php
/**
 * Project: Recipe
 * File: FoodAction.class.php
 * Author: Xnfy520@gmail.com
 * Date: 12-5-29
 * Time: 上午9:06
 */

	class FoodAction extends CommonAction{

		function index(){

			$foodsection = D('FoodSection');
			$foodsectioninfo = $foodsection->relation(true)->where('publish=1')->select();
			$this->assign('foodsectioninfo', $foodsectioninfo);
			$foodarticle = D('FoodArticle');
			$foodarticleinfo  =$foodarticle->relation(true)->where('downloads>2')->select();
			$this->assign('foodarticleinfo', $foodarticleinfo);


			$foodmapf['publish'] = 1;
			$foodmapf['onseason'] = 1;
			$foodmapf['sectionid'] = 7;
			$foodinfof = $foodarticle->where($foodmapf)->limit(9)->select();
			$this->assign('foodinfof',$foodinfof);

			$foodmapv['publish'] = 1;
			$foodmapv['onseason'] = 1;
			$foodmapv['sectionid'] = 8;
			$foodinfov = $foodarticle->where($foodmapv)->limit(9)->select();
			$this->assign('foodinfov',$foodinfov);

			$foodmaps['publish'] = 1;
			$foodmaps['onseason'] = 1;
			$foodmaps['sectionid'] = 9;
			$foodinfos = $foodarticle->where($foodmaps)->limit(9)->select();
			$this->assign('foodinfos',$foodinfos);

			$this->display('food');
		}

		function category(){
			if(isset($_GET['sid']) && !empty($_GET['sid'])){
				$foodarticle = D('FoodArticle');
				$foodarticleinfos  =$foodarticle->relation(true)->where('downloads>2')->select();
				$this->assign('foodarticleinfos', $foodarticleinfos);

				import("ORG.Util.emit_page");
				$count = $foodarticle->where('sectionid='.$_GET['sid'])->count();
				$page = new page($count,10);
				$foodarticleinfo = $foodarticle->relation(true)->limit($page->setlimit())->where('sectionid='.$_GET['sid'])->select();
				$this->assign('foodarticleinfo', $foodarticleinfo);
				$this->assign('fpage',$page->fpage(array(5,6,7)));

				$foodmapf['publish'] = 1;
				$foodmapf['onseason'] = 1;
				$foodmapf['sectionid'] = 7;
				$foodinfof = $foodarticle->where($foodmapf)->limit(9)->select();
				$this->assign('foodinfof',$foodinfof);

				$foodmapv['publish'] = 1;
				$foodmapv['onseason'] = 1;
				$foodmapv['sectionid'] = 8;
				$foodinfov = $foodarticle->where($foodmapv)->limit(9)->select();
				$this->assign('foodinfov',$foodinfov);

				$foodmaps['publish'] = 1;
				$foodmaps['onseason'] = 1;
				$foodmaps['sectionid'] = 9;
				$foodinfos = $foodarticle->where($foodmaps)->limit(9)->select();
				$this->assign('foodinfos',$foodinfos);

				$this->display('foodcai');
			}else{
				$this->error('异常操作');
			}
		}

		function search(){
			$foodarticle = D('FoodArticle');
			import("ORG.Util.emit_page");
			$datas['name'] = array("like","%{$_POST['search']}%");
			$datas['publish'] = 1;
			$count = $foodarticle->where($datas)->count();
			$page = new page($count,10);
			$foodarticleinfo = $foodarticle->limit($page->setlimit())->where($datas)->select();
			$this->assign('foodinfo',$foodarticleinfo);
			$this->assign('fpage', $page->fpage(array(5,6,7)));

			$foodmapf['publish'] = 1;
			$foodmapf['onseason'] = 1;
			$foodmapf['sectionid'] = 7;
			$foodinfof = $foodarticle->where($foodmapf)->limit(9)->select();
			$this->assign('foodinfof',$foodinfof);

			$foodmapv['publish'] = 1;
			$foodmapv['onseason'] = 1;
			$foodmapv['sectionid'] = 8;
			$foodinfov = $foodarticle->where($foodmapv)->limit(9)->select();
			$this->assign('foodinfov',$foodinfov);

			$foodmaps['publish'] = 1;
			$foodmaps['onseason'] = 1;
			$foodmaps['sectionid'] = 9;
			$foodinfos = $foodarticle->where($foodmaps)->limit(9)->select();
			$this->assign('foodinfos',$foodinfos);
			$this->display('foodsearch');
		}

		function foodinfo(){
			if(isset($_GET['sid']) && !empty($_GET['sid'])){
				if(isset($_GET['id']) && !empty($_GET['id'])){
					$foodarticle = D('FoodArticle');
					$foodarticleinfo = $foodarticle->where('sectionid='.$_GET['sid'])->find($_GET['id']);
					$foodarticle->where('sectionid='.$_GET['sid'].' AND id='.$_GET['id'])->setInc('downloads');

					$foodmapf['publish'] = 1;
					$foodmapf['onseason'] = 1;
					$foodmapf['sectionid'] = 7;
					$foodinfof = $foodarticle->where($foodmapf)->limit(9)->select();
					$this->assign('foodinfof',$foodinfof);

					$foodmapv['publish'] = 1;
					$foodmapv['onseason'] = 1;
					$foodmapv['sectionid'] = 8;
					$foodinfov = $foodarticle->where($foodmapv)->limit(9)->select();
					$this->assign('foodinfov',$foodinfov);

					$foodmaps['publish'] = 1;
					$foodmaps['onseason'] = 1;
					$foodmaps['sectionid'] = 9;
					$foodinfos = $foodarticle->where($foodmaps)->limit(9)->select();
					$this->assign('foodinfos',$foodinfos);

					$this->assign('foodarticleinfo',$foodarticleinfo);
				}else{
					$this->error('异常操作');
				}
			}else{
				$this->error('异常操作');
			}
			$this->display('xinxi');
		}

	}